package com.terrace.db.system.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.terrace.db.constant.DBType;
import com.terrace.db.system.dao.DictDataDao;
import com.terrace.db.system.mapper.entity.DictData;
import com.terrace.db.system.service.DictDataService;
import com.terrace.core.mybatis.entity.Pagination;
import com.terrace.core.mybatis.plugin.pagination.PaginationHelper;
import com.terrace.core.spring.datasource.annotation.DataSource;

@Service
@Transactional
@DataSource(name = DBType.ADMIN)
public class DictDataServiceImpl implements DictDataService {
	
	@Autowired
	private DictDataDao dictDataDao;

	@Override
	public int saveDictDataSelective(DictData dictData) {
		return dictDataDao.saveDictDataSelective(dictData);
	}

	@Override
	public int deleteByDictDataId(String dictDataId) {
		return dictDataDao.deleteByDictDataId(dictDataId);
	}

	@Override
	public int updateByDictDataIdSelective(DictData dictData) {
		return dictDataDao.updateByDictDataIdSelective(dictData);
	}

	@Override
	public DictData selectByDictDataId(String dictDataId) {
		return dictDataDao.selectByDictDataId(dictDataId);
	}
	
	@Override
	public boolean selectDictDataRepeat(DictData dictData) {
		DictData temp = new DictData();
		temp.setDict(dictData.getDict());
		temp.setDataValue(dictData.getDataValue());
		PaginationHelper.prepare(false, 2);
		Pagination<DictData> pagination = PaginationHelper.execute(dictDataDao.selectDictDatasBySelective(temp));
		return pagination.getResult().size() >= 1 ? true : false;
	}

	@Override
	public Pagination<DictData> selectDictDatasBySelective(DictData dictData, Pagination<DictData> pagination) {
		PaginationHelper.prepare(pagination);
		return PaginationHelper.execute(dictDataDao.selectDictDatasBySelective(dictData));
	}

	@Override
	public List<DictData> selectDictDatasByCode(String dictCode) {
		return dictDataDao.selectDictDatasByCode(dictCode);
	}

}
